package presentacion;

import integracion.DatabaseManager;
import integracion.EjeDAO;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import share.Eje;


/**
 * Servlet implementation class for Servlet: Sesion
 *
 */
 public class IngresarEje extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
 {
   static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		doAll(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		doAll(request, response);
	}

	private void doAll(HttpServletRequest request, HttpServletResponse response) throws IOException
	{

		if(request.getParameter("accion").equals("Aceptar"))
		{
			System.out.println(request.getParameter("imagen"));


			Eje eje = new Eje();
			eje.setNombre(request.getParameter("nombre"));
			eje.setDescripcion(request.getParameter("descripcion"));


			try
			{
				EjeDAO dao = new EjeDAO(DatabaseManager.getConnection());
				dao.insert(eje);

			} catch (SQLException e)
			{
				e.printStackTrace();
			}
		}

		response.sendRedirect("index.jsp?page=GestionarEje/GestionarEje");
	}
}